<?php

namespace Xsjosg\Zt\App\Webapp\Sixyear251014\Cpanel;

use Xsjosg\Zt\Core\Controllers\CpanelController;
use Xsjosg\Zt\App\Webapp\Sixyear251014\Providers\LogicServiceProvider;
use Xsjosg\Zt\App\Webapp\Sixyear251014\Cpanel\Traits\ShareUidControllerTrait;
use Xsjosg\Zt\App\Webapp\Sixyear251014\Cpanel\Traits\RewardLogControllerTrait;

class Controller extends CpanelController
{
    use RewardLogControllerTrait;
    use ShareUidControllerTrait;
    public function __construct()
    {
        parent::__construct();
        app()->register(LogicServiceProvider::class);
        app('view')->share([
            'appTitle' => '库洛6周年活动',
            /**
             * 如果需要精确控制权限请调用如下方法进行菜单过滤:
             *
             * 'appMenus' => app('cpanel')->filterMenu([
             *     // 菜单配置
             * ]),
             *
             */
            'appMenus' => app('cpanel')->filterMenu([
                ['desc' => '活动配置', 'icon' => 'cog', 'link' => '@setting'],
                ['desc' => '领奖记录', 'icon' => 'cog', 'link' => '@reward_log_list'],
                ['desc' => '分享uid映射记录', 'icon' => 'cog', 'link' => '@share_uid_list'],
            ]),
        ]);

        // 测试环境添加快捷操作按钮
        if (! app()->environment('production')) {
            // 接口文档地址
            // 在生成文档的同时会更新此地址,如已生成文档则需要手动修改
            $appDocUrl = '%doc_url%';
            // 重置数据地址
            // 多个tables,redis_keys使用逗号(,)分隔,中划线开头的table,redis_key会被忽略,不清空数据
            // 例如tables=*,-account表示只清除除了account表之外的其它表
            // 注意table,redis_key不包括专题前缀,例如:表hello_account(其中hello是专题前缀)对应的table为account
            $appCleanUrl = '/tools/debug/clean_data_base?group=webapp&project=sixyear251014&tables=*&redis_keys=*';

            app('view')->share([
                'appDocUrl' => (substr($appDocUrl, 0, 1) == '%') ? '' : $appDocUrl,
                'appCleanUrl' => $appCleanUrl,
            ]);
        }
    }

    public function settingAction()
    {
        $options = [
            'fieldsAppend' => true,
            'fields' => [
                [
                    'name' => 'link_and_award_limit_time',
                    'desc' => '不可生成短链和不能领奖时间',
                    'help' => '为空则不限制',
                    'type' => 'date',
                    'range' => true
                ]
            ]
        ];
        return app('cpanel.view')->createSettingPage($options);
    }
}
